package com.china.bank.demo.config;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Description: Swagger接口文档配置 .<br>
 *
 * @author m-xy
 *     Created By 2019/10/22 15:19
 */
@EnableSwagger2
@Configuration
public class SwaggerConfig {

    @Value("${swagger.enable:true}")
    private boolean enableSwagger;

    /**
     * 初始化swagger app.
     *
     * @return docket object
     */
    @Bean
    public Docket apiBankInfoServer() {
        Predicate<RequestHandler> selector = RequestHandlerSelectors
            .basePackage("com.china.bank.demo.controller");
        return new Docket(DocumentationType.SWAGGER_2)
            .groupName("Bank_Info")
            .enable(enableSwagger)
            .select()
            .apis(Predicates.or(selector))
            .paths(PathSelectors.any())
            .build();
    }
}
